package com.fcat.common.monitor.service.impl;

import com.fcat.common.monitor.entity.Dict;
import com.fcat.common.monitor.mapper.DictMapper;
import com.fcat.common.monitor.service.DictService;
import com.fcat.springboot.mybatis.service.impl.TsuantoneBaseServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DictServiceImpl extends TsuantoneBaseServiceImpl<DictMapper, Dict> implements DictService {

    @Override
    public List<Dict> getListByTypeCode(String typeCode) {
        return mapper.getListByTypeCode(typeCode);
    }

    @Override
    public Map<String, String> getMapByTypeCode(String typeCode) {
        List<Dict> dictList = mapper.getListByTypeCode(typeCode);
        Map<String, String> map = new HashMap<>();
        for (Dict dict : dictList) {
            if (!map.containsKey(dict.getValue())) {
                map.put(dict.getValue(), dict.getName());
            }
        }
        return map;
    }

    @Override
    public Map<String, String> getReverseMapByTypeCode(String typeCode) {
        List<Dict> dictList = mapper.getListByTypeCode(typeCode);
        Map<String, String> map = new HashMap<>();
        for (Dict dict : dictList) {
            if (!map.containsKey(dict.getValue())) {
                map.put(dict.getName(), dict.getValue());
            }
        }
        return map;
    }

    @Override
    public List<Dict> getListByTypeCodes(List<String> typeCodes) {
        Map<String, Object> map = new HashMap<>();
        map.put("typeCodes", typeCodes);
        return mapper.getListByTypeCodes(map);
    }

//    @Override
//    public List<Dict> getNameSortListByTypeCode(String typeCode) {
//        return mapper.getNameSortListByTypeCode(typeCode);
//    }

    @Override
    public String getNameByValue(String value) {
        return mapper.getNameByValue(value);
    }

    @Override
    public List<Dict> getListByTypeCodeAndName(String typeCode, String name) {
        return mapper.getListByTypeCodeAndName(typeCode, name);
    }

    @Override
    public Dict getDictByTypeCodeAndValue(String typeCode, String value) {
        return mapper.getDictByTypeCodeAndValue(typeCode, value);
    }
}